﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using AppLab.Web;

namespace AppLab.Controls
{
    public class DownloadLink : HyperlinkButton
    {
        protected Guid reviewSubmitDataGuid;
        protected string which;
        public DownloadLink(Guid e, string which)
        {
            reviewSubmitDataGuid = new Guid();
            reviewSubmitDataGuid = e;
            this.which = which;
        }

        protected override void OnClick()
        {
            if (reviewSubmitDataGuid != Guid.Empty || which == string.Empty)
            {
                string AbsoluteUri = App.Current.Host.Source.AbsoluteUri;
                //TODO: Hardcode!
                //string AbsolutePath = App.Current.Host.Source.AbsolutePath;
                string AbsolutePath = "/ClientBin/AppLab.xap";
                string HostPath = AbsoluteUri.Substring(0, AbsoluteUri.Length - AbsolutePath.Length);
                switch (which)
                {
                    case "SubmitReleaseNote":
                        NavigateUri = new Uri(string.Format("{0}/GetReleaseNote.ashx?guid={1}", HostPath, reviewSubmitDataGuid.ToString()));
                        break;
                    case "SubmitSelfTest":
                        NavigateUri = new Uri(string.Format("{0}/GetSelfTestResult.ashx?guid={1}", HostPath, reviewSubmitDataGuid.ToString()));
                        break;
                    case "SubmitAnythingElse":
                        NavigateUri = new Uri(string.Format("{0}/GetAnythingElse.ashx?guid={1}", HostPath, reviewSubmitDataGuid.ToString()));
                        break;
                    case "InspectionReport":
                        NavigateUri = new Uri(string.Format("{0}/GetInspectionReport.ashx?guid={1}", HostPath, reviewSubmitDataGuid.ToString()));
                        break;
                    case "SubmitUpgradePackage":
                        NavigateUri = new Uri(string.Format("{0}/GetUpgradePackage.ashx?guid={1}", HostPath, reviewSubmitDataGuid.ToString()));
                        break;
                    default:
                        NavigateUri = new Uri(string.Format("{0}/GetPackage.ashx?guid={1}", HostPath, reviewSubmitDataGuid.ToString()));
                        break;
                }
                TargetName = "_blank";
            }
            base.OnClick();
        }
    }
}
